/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.ContentTypeHeader;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class ContentTypeHeaderImpl extends ParametrizedHeaderBase implements ContentTypeHeader {
    private String contentType;
    private String contentSubtype;

    private static final ContentTypeHeaderParser parser = new ContentTypeHeaderParser();

    public ContentTypeHeaderImpl() {
        super(ContentTypeHeader.NAME);
    }

    public ContentTypeHeaderImpl(byte[] data, int start, int end) {
        super(ContentTypeHeader.NAME, data, start, end);
    }

    public Object clone() {
        final ContentTypeHeaderImpl header = new ContentTypeHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.cloneParameters(this);
            header.contentType = this.contentType;
            header.contentSubtype = this.contentSubtype;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return contentType + '/' + contentSubtype;
    }

    /**
     * Sets value of media type of Header with Content Type.
     *
     * @param contentType the new string value of the content type
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the contentType value.
     */
    public void setContentType(String contentType) throws ParseException {
        parse();
        this.contentType = contentType;
        invalidateHeaderData();
    }

    /**
     * Gets media type of Header with Content type.
     *
     * @return media type of Header with Content type.
     */
    public String getContentType() {
        parse();
        return this.contentType;
    }

    /**
     * Sets value of media subtype of Header with Content sub-type.
     *
     * @param contentSubType the new string value of the content sub-type.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the contentSubType value.
     */
    public void setContentSubType(String contentSubType) throws ParseException {
        parse();
        this.contentSubtype = contentSubType;
        invalidateHeaderData();
    }

    /**
     * Gets media sub-type of Header with Content sub-type.
     *
     * @return media sub-type of Header with Content sub-type.
     */
    public String getContentSubType() {
        parse();
        return this.contentSubtype;
    }
}
/*
 * $Log$
 */